<?php if (!defined('THINK_PATH')) exit();?><table id="dg"></table>
<!--工具栏 -->
<style type="text/css">
     .table-btn-separator{
   
  }
</style>
<div id="tiretool">
    <table>
        <tr>
            <?php if($_SESSION[C('USER_AUTH_KEY')] > 0 and $_SESSION[C('USER_AUTH_KEY')] < 3): ?><td>
                    <a href="#" id="aaa1" class="easyui-linkbutton" onclick='show_add()' data-options="iconCls:'icon-standard-folder-page',plain:true">添加</a>
                    <a href="#" class="easyui-linkbutton" onclick='dele()' data-options="iconCls:'icon-standard-page-white-delete',plain:true">删除</a>
                    <a href="#" class="easyui-linkbutton" onclick='show_edit()' data-options="iconCls:'icon-standard-application-edit',plain:true">编辑</a></td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td><?php endif; ?>
            <td>
             <div style="float:left;">
             <span style="padding-left: 6px;">请输入打印数量：</span>
                   
                    <input id="num" class="easyui-numberspinner" style="width:60px;"  
        required="required" data-options="min:1,max:99,editable:true,value:1">
                </div>
                 <a href="#" class="easyui-linkbutton" onclick="printshow()" data-options="iconCls:'icon-standard-printer-add',plain:true">打印预览</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
        
           
            <td>

          <!--   <a href="#" class="easyui-linkbutton" onclick="printshow()" data-options="iconCls:'icon-standard-magnifier',plain:true">搜索</a> -->

                <div style="float:right;">
                    <input id='searchbox' class="easyui-searchbox" data-options="" style="width:400px;"></input>
                </div>
                <div id="tiremm" style="width:400px">
                    <div data-options="name:'th',iconCls:'icon-standard-table-edit',selected:true">零件图号</div>
                    <div data-options="name:'coder',iconCls:'icon-standard-date-magnify'">关系码</div>
                    <div data-options="name:'mc',iconCls:'icon-standard-table-multiple'">零件名称</div>
                    <div data-options="name:'gys',iconCls:'icon-standard-tag-blue'">供应商</div>
                </div>
            </td>
                <td>
               <!--  <a href="#" class="easyui-linkbutton" onclick="excel()" data-options="iconCls:'icon-standard-page-white-excel',plain:true">导出</a> -->
                <!-- <a href="#" class="easyui-linkbutton" onclick="view()" data-options="iconCls:'icon-standard-application-view-gallery',plain:true">查看</a>
                <a href="#" class="easyui-linkbutton" onclick="show_pinlun()" data-options="iconCls:'icon-standard-building-add',plain:true">评论</a> -->
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
             <td>
                <a href="#" class="easyui-linkbutton" onclick="reload()" data-options="iconCls:'icon-standard-arrow-refresh',plain:true">刷新</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
        </tr>
        <tr class="datagrid-toolbar">
        <?php if($_SESSION[C('USER_AUTH_KEY')] > 0 and $_SESSION[C('USER_AUTH_KEY')] < 3): ?><td colspan='9'>
                       <div class="datagrid-toolbar"></div>
             </td>
            <?php else: ?>
            <td colspan='7'>
                       <div class="datagrid-toolbar"></div>
             </td><?php endif; ?>
           
           
            
        </tr>
         <tr>
   <?php if($_SESSION[C('USER_AUTH_KEY')] > 0 and $_SESSION[C('USER_AUTH_KEY')] < 3): ?><td colspan='9'>
                      <label for="coder">关系码:</label>  
        <input class="easyui-validatebox" type="text" name="coder" id="scoder" data-options="" />
                      <label for="coder">零件图号:</label>  
        <input class="easyui-validatebox" type="text" name="th" id="sth" data-options="" />
                      <label for="coder">零件名称:</label>  
        <input class="easyui-validatebox" type="text" name="mc" id="smc" data-options="" />
                      <label for="coder">供应商:</label>  
        <input class="easyui-validatebox" type="text" name="gys" id="sgys" data-options="" />   
<a href="#" class="easyui-linkbutton" onclick="doSearch()" data-options="iconCls:'icon-search',plain:true">搜索</a>

             </td>
            <?php else: ?>
            <td colspan='7'>
                        <label for="coder">关系码:</label>  
        <input class="easyui-validatebox" type="text" name="coder" id="scoder" data-options="" />
                      <label for="coder">零件图号:</label>  
        <input class="easyui-validatebox" type="text" name="th" id="sth" data-options="" />
                      <label for="coder">零件名称:</label>  
        <input class="easyui-validatebox" type="text" name="mc" id="smc" data-options="" />
                      <label for="coder">供应商:</label>  
        <input class="easyui-validatebox" type="text" name="gys" id="sgys" data-options="" />   
<a href="#" class="easyui-linkbutton" onclick="doSearch()" data-options="iconCls:'icon-search',plain:true">搜索</a>
             </td><?php endif; ?>
           
        </tr>
    </table>
</div>
<script type="text/javascript">
  
</script>
<style>
	.uploadpic{
		float:left;
		width: 295px;
		text-align:center;
		height:165px;
	}
	.uploadpic h3{
		text-align:left;
		border:1px solid  #95B8E7;
		float:left;
		padding:4px;
		background-color:#95B8E7;
		color:#FFF;
	}
	.up-content{
		border:1px solid  #95B8E7;
		padding:4px;
	}
	.w10{
		float:left;
		width:10px;
		color:#FFF;
	}
</style>
<div id="add" class="easyui-dialog" style="width: 644px; height: 148px; padding: 0px; overflow: hidden;" title="&nbsp;&nbsp;添加关系码" data-options="iconCls:'icon-standard-folder-page',buttons:'#dlg-add',closed:true,resizable:false,modal:false,closable:true">
	<form id="add_form" action="/TIREBAR/index.php/Home/Quality/add_quality" enctype="multipart/form-data" method="post" >
		<table width="100%" cellspacing="0" class="table_form">
	<tr>
		<th width="80">基本信息</th>
		<td style="height: 40px" colspan="3">
			<div>
				<label>关系码：
					<input id="coder" name="coder" class="easyui-validatebox" style="width: 200px"data-options="required:true" />
				</label>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<label for="creattime">供应商：
					<input id="gys" name="gys" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>
			</div>

			<div style="padding:10px 0 0 0 ">

				<label for="laiyuan">名&nbsp;&nbsp;&nbsp;&nbsp;称：
					<input id="mc" name="mc" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label for="zrdw">图&nbsp;&nbsp;&nbsp;&nbsp;号：
					<input id="th" name="th" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>
			</div>
		</td>
	</tr>
	
</table>
	<input type="hidden" name="userid" id="userid" value= <?php echo ($_SESSION['uid']); ?>>
	</form>
</div>

<div id="dlg-add">
	<div class="tool_tip">添加关系码后会在列表中出现！！</div>
	<a href="#" id="addok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
		onclick="add()">确认</a>
	<a href="#" class="easyui-linkbutton"
		data-options="iconCls:'icon-cancel'"
		onclick="javascript:$('#add').dialog('close')">取消</a>
</div>

<div id="edit" class="easyui-dialog" style="width:646px;height:149px;padding:0px;overflow:hidden;"     
        title="&nbsp;&nbsp;编辑关系码"  data-options="iconCls:'icon-standard-folder-page',buttons:'#dlg-edit',closed:true,resizable:false,modal:true,closable:true">  
            

    <form id="edit_form"  method="post" >    
        <table width="100%" cellspacing="0" class="table_form">
			<tr >
			<th width="80">基本信息</th>
				<td style="height: 40px" colspan="3">
				
				<div>
				<label>关系码：
					<input id="coder" name="coder" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<label for="creattime">供应商：
					<input id="gys" name="gys" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>
			</div>

			<div style="padding:10px 0 0 0 ">

				<label for="laiyuan">名&nbsp;&nbsp;&nbsp;&nbsp;称：
					<input id="mc" name="mc" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label for="zrdw">图&nbsp;&nbsp;&nbsp;&nbsp;号：
					<input id="th" name="th" class="easyui-validatebox" style="width: 200px" data-options="required:true"/>
				</label>
				<input type="hidden" name="id" value="value">
			</div>


				</td>


			</tr>

		</table>
    </form>  

</div> 
<div id="dlg-edit">
	<div class="tool_tip">只有自己发布的质量信息才能进行编辑！！</div>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="edit()">确认</a>    
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#edit').dialog('close')">取消</a>    
</div>




<style type="text/css">
	.codetb{
	width:300px;
	}
.lal{
	font-size:8px;
  font-weight: bold;
  color:#999999;
	}
  .val{
font-size:12px;
  font-weight: bold;
  }
.coder{
  width:80px;
 /* background-color: red;*/
}
.footer{
 
  font-size:12px;
  font-weight: bold;
}
</style>
<div id="printdialog" class="easyui-dialog" style="width:450px;height:600px;padding:0px;" title="&nbsp;&nbsp;编辑记录" data-options="iconCls:'icon-standard-printer-add',buttons:'#dlg-edit',closed:true,resizable:false,modal:true,closable:true">

<div id="contarin"></div>

</div>
<div id="dlg-edit" >
    <div class="tool_tip" id="tip">只有自己发布的质量信息才能进行编辑！！</div>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-standard-printer',plain:true" onclick="printCoder()">打印</a>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="javascript:$('#printdialog').dialog('close')">取消</a>
</div>

<script type="text/javascript">
var printCoder=function(){
	// alert("带你");
	// $("#contarin").printArea();
	 $("#contarin").print({
            globalStyles: true,
            mediaPrint: true,
            stylesheet: null,
            noPrintSelector: ".no-print",
            iframe: true,
            append: null,
            prepend: null,
            manuallyCopyFormValues: true,
            deferred: $.Deferred(),
            timeout: 750,
            title: null,
            doctype: '<!doctype html>'
    });
}
</script>







<script type="text/javascript">
	$('#dg').datagrid({
	url : '/TIREBAR/index.php/Home/Trie/read',
	toolbar : '#tiretool',
	pagination : true,
	fit : true,
	width : function() {
		return document.body.clientWidth * 0.9
	},
	nowrap : false,
	collapsible : true,
	fitColumns : true,
	autoRowHeight : false,
	striped : true,//交替行
	singleSelect : true,//只允许选择一行
	rownumbers : true,
	border : false,
	sortName : 'id',
	sortOrder : 'desc',//倒序排列
	remoteSort : false,
	pageSize : 50,
	method : "post",
	pageList : [ 10, 15, 20, 40, 50, 100, 200 ],
	columns : [ [
			{
				field : 'id',
				checkbox : true
			},
			{
				field : 'coder',
				title : '关系码',
				width : 180
				// formatter : function(val, rowdata, index) {
				// 	return '<a class="grid_pic" onclick="showpic()"></a>'
				// }
			},

			{
				field : 'th',
				title : '零件图号',
				width : 180
				
			},
			{
				field : 'mc',
				title : '零件名称',
				width : 200
			},
			{
				field : 'gys',
				title : '供应商',
				width : 100,
				align : 'left'		
			}

	] ]
});

      function doSearch(){  
    $('#dg').datagrid('load',{  
        mc: $('#smc').val(),  //车间
        th: $('#sth').val(),//班组
        gys: $('#sgys').val(),//工位
        coder: $('#scoder').val()//工位
        
    });  
 
}
	//
	$('#searchbox').searchbox({
		searcher : function(value, name) {
			/*	$('#dg').datagrid('load', {
		 		"searchKey" : name,
				"searchValue" : value
			}); */
				
			 switch (name)
			 {
			 case 'coder':
			 $('#dg').datagrid('load',{
			 coder:value
			 });
			 break;
			 case 'th': 
			 $('#dg').datagrid('load',{
			 th:value
			 });
			 break;
			 case 'mc': 
			 $('#dg').datagrid('load',{
			 mc:value
			 });
			 break;
			 case 'gys': 
			 $('#dg').datagrid('load',{
			 gys:value
			 });
			 break;
			
			 } 
		},
		menu : '#tiremm',
		prompt : '请输入搜索内容'
	});

	//对Date的扩展，将 Date 转化为指定格式的String 
	//月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
	//年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
	//例子： 
	//(new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
	//(new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
	Date.prototype.Format = function(fmt) { //author: meizz 
		var o = {
			"M+" : this.getMonth() + 1, //月份 
			"d+" : this.getDate(), //日 
			"h+" : this.getHours(), //小时 
			"m+" : this.getMinutes(), //分 
			"s+" : this.getSeconds(), //秒 
			"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
			"S" : this.getMilliseconds()
		//毫秒 
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
		for ( var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
						: (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}

	//打开添加窗口

	function showupload() {
		$('#showupload').window('open'); // open a window 	
	}

	function show_add() {
		 $("#addok").linkbutton("enable");
		var myDate = new Date();
		var date;

		date = new Date(new Date()).Format("yyyy-MM-dd");
		$('#add').window('open'); // open a window 
		$('#add_form').form('load', {
			coder : '',
			th : '',
			mc : '',
			gys : ''
});

}

	//添加记录
	function add() {
 $("#addok").linkbutton("disable");
		$('#add_form').form('submit', {

			url : '/TIREBAR/index.php/Home/Trie/add_coder',

			success : function(data) {
				$("#dg").datagrid("reload");

				$.messager.alert('添加关系码', data, 'info');
				$('#add').dialog('close')

			}
		});
	}



//显示打印页面
	function printshow() {
var num = $('#num').numberbox('getValue');//打印数量

var row = $('#dg').datagrid("getSelected");
		if(num){
				if (row) {

			$("#printdialog").dialog("open").dialog('setTitle', '&nbsp;&nbsp;打印预览');
			creator();

			// $("#print_form").form("load", row);

		} else {
			$.messager.alert("请选择要编辑的行", "请选择要编辑的行！", "info");
		}


		}else{
			$.messager.alert("请选择", "请选择要生成的标签数量！", "info");
		}
	
	}
	function reload() {
		$('#dg').datagrid('reload', {   
		    cx: '' 
		});
	}

	//删除		
	function dele() {
		var row = $('#dg').datagrid("getSelected");
		if (row.userid == "<?php echo ($_SESSION[ 'uid']); ?>" || "<?php echo ($_SESSION[ 'group_id']); ?>"=="1" )  {
			if (row) {
				$.messager.confirm('确认', '您确定要删除此关系码吗?', function(r) {
					if (r) {
						$.post('/TIREBAR/index.php/Home/Trie/del', {
							id : row.id
						}, function(data) {
							if (data) {
								$.messager.alert('删除关系码', data, 'info');
								$("#dg").datagrid("reload");
							} else {
								$.messager.show({ // show error message  
									title : '错误',
									msg : result.errorMsg
								});

							}
						}, 'text');
					}
				});
			} else {
				$.messager.alert("请选择", "请选择要删除的关系码！", "info");
			}

		} else {

			$.messager.alert("无法删除", "此关系码非您创建，无法删除！", "info");
		}

	}

	function show_edit() {

		var row = $('#dg').datagrid("getSelected");

		if (row) {

			$("#edit").dialog("open").dialog('setTitle', '&nbsp;&nbsp;编辑关系码');

			$("#edit_form").form("load", row);

		} else {
			$.messager.alert("请选择要编辑的行", "请选择要编辑的行！", "info");
		}

	}

 	function edit() {
		var row = $("#dg").datagrid("getSelected");

		$('#edit_form').form('submit', {
			type:'POST',
			 url : '/TIREBAR/index.php/Home/Trie/edit',
			success : function(data) {
				$("#dg").datagrid("reload");
				$.messager.alert('编辑关系码', data, 'info');
				$('#edit').dialog('close')

			}
		});
	} 

	function page() {
		return $('#dg').datagrid('options').pageNumber;
	}
	function pagesize() {
		return $('#dg').datagrid('options').pagesize;
	}
	function excel() {
		
		var grid = $('#dg');  
		var options = grid.datagrid('getPager').data("pagination").options; 
		var pageNumber = options.pageNumber;  
		var pageSize=options.pageSize; 
		window.location.href='/TIREBAR/index.php/Home/Quality/out/page/'+pageNumber+'/pagesize/'+pageSize;	
	}
	
	function down(){
		var row = $("#dg").datagrid("getSelected");
		var id=row.id;	
		window.location.href='/TIREBAR/index.php/Home/Quality/down/id/'+id;
	}
	function show_pinlun() {

		var row = $('#dg').datagrid("getSelected");
		
		if (row) {

			
			$('#pl').window('open');
			$("#hideid").val(row.id);
			$("#hidepl").val(row.pinglun);
			


		} else {
			$.messager.alert("请选择要进行评论的记录", "请选择要评论的记录！", "info");
		}

	}

	function print_view() {
		$("#printview").jqprint({
			debug : true,
			printContainer : true
		});
	}


function pinglun(){
		 var row = $("#dg").datagrid("getSelected");

			$('#add_pl').form('submit', {
				type:'POST',
				 url : '/TIREBAR/index.php/Home/Quality/pinglun',
				success : function(data) {
					$("#dg").datagrid("reload");
					$.messager.alert('评论质量信息', data, 'info');
					$('#pl').dialog('close')

				}
			});
	 }


//生成二维码格式

	var creator=function(){
		$("#contarin").html("");//清空
		var row = $('#dg').datagrid("getSelected");
		var num = $('#num').numberbox('getValue');//打印数量
		var bartxt=""
		var barid=new Array();
		for (var i=1;i<=num;i++)
{
	barid[i]="b"+i;

	if(i<10){
bartxt=row.coder+Math.round(new Date().getTime()/1000)+'0'+i;

	}else{
		bartxt=row.coder+Math.round(new Date().getTime()/1000)+i;
	}
	var html="<table class='codetb' border='0'><tr><td colspan='2'><span class='val'>"+row.mc+"</span></td><td rowspan='5' class='coder'><div id='"+barid[i]+"'></div></td></tr><tr><td colspan='2'><span class='val'>"+row.th+"</span></td></tr><tr><td colspan='2'  class='footer'>"+bartxt+"</td></tr><tr><td><span class='val'>"+row.gys+"</span></td><td><span class='val'>"+getNowFormatDate()+"</span></td></tr></table>";

	$("#contarin").append(html);
	$('#b'+i).qrcode({width: 64,height: 64,text: bartxt,background:'#ffffff',foreground:'#000000'});
// 	var canvas=('#b'+i+' canvas');
// 	var img =canvas.toDataURL("image/png");
// $('#b'+i).html('<img src="'+img+'"/>');
var ca=$('#b'+i).children("canvas");

 var img =ca[0].toDataURL("image/png");
 $('#b'+i).html('<img src="'+img+'"/>');
// $('#b'+i).html('<img src="'+img+'"/>');
	if(i!=num){
			$("#contarin").append("<div style='page-break-after: always;'></div>"); 
	}

$('#tip').html("共生成"+num+"条标签！");

}

	}
//日期格式化
	function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    // var currentdate = year + seperator1 + month + seperator1 + strDate
    //         + " " + date.getHours() + seperator2 + date.getMinutes()
    //         + seperator2 + date.getSeconds();
      var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

</script>